clear all
set more off

**********************************
*** Set where is the dataset and upload it
**********************************

use "D:\Dropbox\1. Research\0. Pubblications\2020 RESTat\RESTAT\2. Tex & Replication\2.data_consumers.dta"

******************************************
***Figures in the Draft
******************************************

************Formatting

gen price2 = price
gen price3 = price

replace price2 = 1 if price==15 & item==1
replace price2 = 2 if price==20 & item==1
replace price2 = 3 if price==25 & item==1
replace price2 = 4 if price==30 & item==1
replace price2 = 5 if price==35 & item==1

replace price2 = 1 if price==60 & item==2
replace price2 = 2 if price==70 & item==2
replace price2 = 3 if price==80 & item==2
replace price2 = 4 if price==90 & item==2
replace price2 = 5 if price==100 & item==2

replace price2 = 1 if price==20 & (item==3|item==4)
replace price2 = 2 if price==30 & (item==3|item==4)
replace price2 = 3 if price==40 & (item==3|item==4)
replace price2 = 4 if price==50 & (item==3|item==4)
replace price2 = 5 if price==60 & (item==3|item==4)

label define pr 1 "15" 2 "20" 3 "Base" 4 "Alt1" 5 "Alt 2" 


replace price = price2

label val price pr

label define it 1 "veg meal" 2 "biriyani" 3 "rice and fish" 4 "biriyani" 

label val item it

*label define it2 1 "veg meal (base: Rs 25)" 2 "ch biriyani (base: Rs 80)" 3 "rice and fish (base: Rs 40)" 4 "ch biriyani (base: Rs 40)" 

*****AN OVERALL GRAPH, ACROSS ITEMS 

gen option = .

replace option = 1 if hygien==1 & poster==0 & known==1
replace option = 2 if hygien==0 & poster==1 & known==1
replace option = 3 if hygien==1 & poster==1 & known==1

replace option = 4 if hygien==1 & poster==0 & known==0
replace option = 5 if hygien==0 & poster==1 & known==0
replace option = 6 if hygien==1 & poster==1 & known==0

gen B = (q==2)

label define pr_short 1 "15" 2 "20" 3 "B" 4 "A1" 5 "A2" 

label val price pr_short

label define opt 1 "K=1,H=1,P=0" 2 "K=1,H=0,P=1" 3 "K=1,H=1,P=1" 4 "K=0,H=1,P=0" 5 "K=0,H=0,P=1" 6 "K=0,H=1,P=1"
label define opt_1 1 "K, H" 2 "K, P" 3 "K, H, P" 4 "U, H" 5 "U, P" 6 "U, H, P"

label val option opt_1

graph bar (mean) B if  const==0 , over(price) over(option) /*
*/ ytitle("Share Choosing Alternative") /*
*/ title("Default: Known, bad hygiene, no poster, baseline price")subtitle("K: Known, U: Unkown, H: Good hygiene, P: Has poster ") /*
*/plotregion(fcolor(white)) graphregion(fcolor(white))

***Overall regressions: 

areg B price hygien known poster if const==0, absorb(id) r cluster(block)
areg B price hygien known poster if const==0 & item==1, absorb(id) r cluster(block)
areg B price hygien known poster if const==0 & item==2, absorb(id) r cluster(block)
areg B price hygien known poster if const==0 & item==3, absorb(id) r cluster(block)
areg B price hygien known poster if const==0 & item==4, absorb(id) r cluster(block)


****ACROSS ITEMS, by education

***Using completed secondary schooling

gen highedu = (educ>=9)

gen B_highedu = (q==2 & highedu==1)
replace B_highedu=. if highedu==0
gen B_no_highedu = (q==2 & highedu==0)
replace B_no_highedu=. if highedu==1

graph bar (mean) B_highedu B_no_highedu if  const==0 , over(price) over(option) /*
*/ legend( label(1 "Complete Secondary Edu") label(2 "Incomeplete Secondary Edu") ) /*
*/ ytitle("Share Choosing Alternative") ylabel(0.2(0.2)1) /*
*/ title("Default: Known, bad hygiene, no poster, baseline price")subtitle("K: Known, U: Unkown, H: Good hygiene, P: Has poster ") /*
*/plotregion(fcolor(white)) graphregion(fcolor(white))

****ACROSS ITEMS, by income

***Note, highinc defined by income>=20,000

gen highinc = (income>=3)

gen B_highinc = (q==2 & highinc==1)
replace B_highinc=. if highinc==0
gen B_no_highinc = (q==2 & highinc==0)
replace B_no_highinc=. if highinc==1

graph bar (mean) B_highinc B_no_highinc if  const==0 , over(price) over(option) /*
*/ legend( label(1 "Income > Rs 20,000") label(2 "Income < Rs 20,000") ) /*
*/ ytitle("Share Choosing Alternative") ylabel(0.2(0.2)1) /*
*/ title("Default: Known, bad hygiene, no poster, baseline price")subtitle("K: Known, U: Unkown, H: Good hygiene, P: Has poster ") /*
*/plotregion(fcolor(white)) graphregion(fcolor(white))

***ACROSS ITEMS, by whether hygiene is most important factor 

gen B_hyg = (q==2 & most_imp==2)
replace B_hyg=. if most_imp!=2
gen B_no_hyg = (q==2 & most_imp!=2)
replace B_no_hyg=. if most_imp==2

graph bar (mean) B_hyg B_no_hyg if  const==0 , over(price) over(option) /*
*/ legend( label(1 "Hygiene Most Important") label(2 "Hygiene Not Most Important") ) /*
*/ ytitle("Share Choosing Alternative") ylabel(0.2(0.2)1) /*
*/ title("Default: Known, bad hygiene, no poster, baseline price")subtitle("K: Known, U: Unkown, H: Good hygiene, P: Has poster ") /*
*/plotregion(fcolor(white)) graphregion(fcolor(white))

***ACROSS ITEMS, by whether they can detect contaminants 

gen B_det = (q==2 & det==4)
replace B_det=. if det<4
gen B_no_det = (q==2 & det<4)
replace B_no_det=. if det==4

graph bar (mean) B_det B_no_det if  const==0 , over(price) over(option) /*
*/ legend( label(1 "Can Detect Contaminants") label(2 "Cannot Detect Contaminants") ) /*
*/ ytitle("Share Choosing Alternative") ylabel(0.2(0.2)1)/*
*/ title("Default: Known, bad hygiene, no poster, baseline price")subtitle("K: Known, U: Unkown, H: Good hygiene, P: Has poster ") /*
*/plotregion(fcolor(white)) graphregion(fcolor(white))


***SEPARATELY BY ITEM: 
***Education: 

***Known, good hygiene, no poster

graph bar (mean)   B_highedu B_no_highedu if const==0 & hygien==1 & poster==0 & known==1, over(price) over (item) /*
*/ legend( label(1 "Complete Secondary Edu") label(2 "Incomeplete Secondary Edu") ) /*
*/ ytitle("Share Choosing Alternative") ylabel(0.2(0.2)1)/*
*/ title("Alternative: Known, good hygiene, no poster")subtitle("Default: Known, bad hygiene, no poster") /*
*/plotregion(fcolor(white)) graphregion(fcolor(white))

***Known, bad hygiene, has poster

graph bar (mean)   B_highedu B_no_highedu if const==0 & hygien==0 & poster==1 & known==1, over(price) over (item) /*
*/ legend( label(1 "Complete Secondary Edu") label(2 "Incomeplete Secondary Edu") ) /*
*/ ytitle("Share Choosing Alternative") ylabel(0.2(0.2)1)/*
*/ title("Alternative: Known, bad hygiene, has poster")subtitle("Default: Known, bad hygiene, no poster") /*
*/plotregion(fcolor(white)) graphregion(fcolor(white))

***Known, good hygiene, has poster

graph bar (mean)   B_highedu B_no_highedu if const==0 & hygien==1 & poster==1 & known==1, over(price) over (item) /*
*/ legend( label(1 "Complete Secondary Edu") label(2 "Incomeplete Secondary Edu") ) /*
*/ ytitle("Share Choosing Alternative") ylabel(0.2(0.2)1)/*
*/ title("Alternative: Known, good hygiene, has poster")subtitle("Default: Known, bad hygiene, no poster") /*
*/plotregion(fcolor(white)) graphregion(fcolor(white))


***Unknown, good hygiene, no poster

graph bar (mean)  B_highedu B_no_highedu if  const==0 & hygien==1 & poster==0 & known==0, over(price) over (item) /*
*/ legend( label(1 "Complete Secondary Edu") label(2 "Incomeplete Secondary Edu") ) /*
*/ ytitle("Share Choosing Alternative") ylabel(0.2(0.2)1)/*
*/ title("Alternative: Unknown, good hygiene, no poster")subtitle("Default: Known, bad hygiene, no poster") /*
*/plotregion(fcolor(white)) graphregion(fcolor(white))

***Unknown, bad hygiene, has poster

graph bar (mean)   B_highedu B_no_highedu if const==0 & hygien==0 & poster==1 & known==0, over(price) over (item) /*
*/ legend( label(1 "Complete Secondary Edu") label(2 "Incomeplete Secondary Edu") ) /*
*/ ytitle("Share Choosing Alternative") ylabel(0.2(0.2)1)/*
*/ title("Alternative: Unknown, bad hygiene, has poster")subtitle("Default: Known, bad hygiene, no poster") /*
*/plotregion(fcolor(white)) graphregion(fcolor(white))

***Unknown, good hygiene, has poster

graph bar (mean)   B_highedu B_no_highedu if const==0 & hygien==1 & poster==1 & known==0, over(price) over (item) /*
*/ legend( label(1 "Complete Secondary Edu") label(2 "Incomeplete Secondary Edu") ) /*
*/ ytitle("Share Choosing Alternative") ylabel(0.2(0.2)1)/*
*/ title("Alternative: Unknown, good hygiene, has poster")subtitle("Default: Known, bad hygiene, no poster") /*
*/plotregion(fcolor(white)) graphregion(fcolor(white))


***** table conditional logit ****

clogit y  price known hygiene   poster const,group(cluster) , if item==1
outreg2 using wp, replace tex
nlcom (_b[hygiene])/(-_b[price])

clogit y  price known hygiene   poster const,group(cluster) , if item==2
outreg2 using wp, tex
nlcom (_b[hygiene])/(-_b[price])

clogit y  price known hygiene   poster const,group(cluster) , if item==3
outreg2 using wp, tex
nlcom (_b[hygiene])/(-_b[price])

clogit y  price known hygiene   poster const,group(cluster) , if  item==4
outreg2 using wp, tex
nlcom (_b[hygiene])/(-_b[price])

clogit y  price known hygiene   poster const,group(cluster)  
outreg2 using wp, tex
nlcom (_b[hygiene])/(-_b[price])
 
***** table conditional logit interactions ******
gen highhygien=most_imp==2
gen dethigh=det==4

clogit y  price known hygiene##highedu   poster const,group(cluster)  
outreg2 using wp2, keep(1.hygiene 1.hygiene#1.highedu) replace tex
clogit y  price known hygiene##highinc   poster const,group(cluster)  
outreg2 using wp2,  keep(1.hygiene 1.hygiene#1.highinc) tex 
clogit y  price known hygiene##highhygien   poster const,group(cluster)  
outreg2 using wp2, keep(1.hygiene 1.hygiene#1.highhygien)  tex 
clogit y  price known hygiene##dethigh   poster const,group(cluster)  
outreg2 using wp2, keep(1.hygiene 1.hygiene#1.dethigh)   tex 






